﻿using Cemit.NetFramework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using UnityEngine;

namespace Cemit.NetFramework.Demo.Example
{
    public class GameManager : MonoBehaviour
    {
        async void Awake()
        {
            var socket = PolyNetwork.CreateSocket();
            var report = await socket.Connect("127.0.0.1", 2345);

            if (!report.isSucceed)
            {
                return;
            }

            socket.AddDynamicMessageListener("NewPlayer", r => Debug.Log($"新的玩家加入：{r.message.account}"));

            dynamic loginInfo = new
            {
                account = 123456,
                password = 123456
            };

            DynamicReport loginReport = await socket.Send("login", loginInfo); 
            Debug.Log(loginReport.message);

            loginInfo = new
            {
                account = 123456,
                password = 123
            };

            loginReport = await socket.Send("login", loginInfo); 
            Debug.Log(loginReport.message);
        }
    }
}